package com.buka.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class JDBCConfig {

    private static String url;
    private static String userName;
    private static String passwd;
    private static String driverName;
    private static int poolSize = 10;

    public static String getUrl() {
        return url;
    }

    public static String getUserName() {
        return userName;
    }

    public static String getPasswd() {
        return passwd;
    }

    public static String getDriverName() {
        return driverName;
    }

    public static int getPoolSize() {
        return poolSize;
    }

    //程序初始化的时候加载
    //静态代码块  只加载一次 类被使用的时候就加载了
    static {
        //加载配置文件  类加载器加载文件 一般用相对路径 ，根是项目文件夹，resource标记资源文件夹
        InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("jdbc.properties");
        //解析配置文件
        Properties properties = new Properties();
        try {
            //加载并解析
            properties.load(resourceAsStream);
            url = properties.getProperty("url");
            userName = properties.getProperty("userName");
            passwd = properties.getProperty("passwd");
            driverName = properties.getProperty("driverName");
            poolSize = Integer.parseInt(properties.getProperty("poolSize"));

        } catch (IOException e) {
            e.printStackTrace();
        }


    }



}
